package com.cn.ryc.controller;

import com.cn.ryc.model.Staff;
import com.cn.ryc.service.StaffService;
import com.cn.ryc.util.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/staff")
public class StaffController {

    // 注入StaffService
    @Autowired
    private StaffService staffService;

    // 获取所有员工
    @GetMapping("/list")
    public ResponseEntity<ApiResponse<List<Staff>>> getAllStaff() {
        return staffService.getAllStaff();
    }

    // 根据id获取员工
    @GetMapping("/{id}")
    public ResponseEntity<ApiResponse<Staff>> getStaffById(@PathVariable Long id) {
        return staffService.getStaffById(id);
    }

    // 添加员工
    @PostMapping("/add")
    public ResponseEntity<ApiResponse<String>> addStaff(@RequestBody Staff staff) {
        System.out.println(staff);
        return staffService.addStaff(staff);
    }

    // 更新员工
    @PutMapping("/update")
    public ResponseEntity<ApiResponse<String>> updateStaff(@RequestBody Staff staff) {
        return staffService.updateStaff(staff);
    }

    // 根据id删除员工
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<ApiResponse<String>> deleteStaff(@PathVariable Long id) {
        return staffService.deleteStaff(id);
    }
} 